<?php

class Friendship_IndexController extends Zend_Controller_Action
{

    public function init()
    {
		$this->_helper->layout()->setLayout('abc');
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	//echo 'aaaaaaaaaaaaaaaa';
    	$fs = new Friendship_Model_Dbtable_Friendship();
    	echo '<pre>';
    		print_r($fs->getFriends('1'));
    	echo '</pre>';	
    }
	
	public function addfriendAction()
	{
		$this->getHelper('viewRenderer')->setNoRender();
		$user1 = $_POST['user1'];
		$user2 = $_POST['user2'];
		$af = new Friendship_Model_Dbtable_RequestFriendship();
		$af -> addrequestfriends($user1,$user2);
		
		$name_fr = new User_Model_DbTable_Users();
		$name_f_r = $name_fr -> getnameuser($user1);
		$kq=array('name_f_r'=>$name_f_r);
		echo Zend_Json::encode($kq);
	}

	public function testAction()
	{
		$this->getHelper('viewRenderer')->setNoRender();
		$cfs = new Friendship_Model_Dbtable_RequestFriendship();
		print_r ($cfs -> checkrequestfriendships('17'));
	}
	
	public function getnumrequestfriendshipsAction(){
		$this->getHelper('viewRenderer')->setNoRender();
		$iduser = $_POST['iduser'];
		$tong = $_POST['tong'];
		$crf = new Friendship_Model_Dbtable_RequestFriendship();
		$friend_request = $crf ->getrequestfriendships($iduser);
		$num_friend_request = count($friend_request);
		if($num_friend_request != $tong)
		{
			//$sql = "select request_friendship_user1 from request_friendships where request_friendship_user1 = ".$iduser." and request_friendship_read = 0"
			
		}
		$kq=array('num_friend_request'=>$num_friend_request,'array_friend_request'=>$friend_request);
		echo Zend_Json::encode($kq);
	}
	
	//IndexAction cua User su dung
	public function getrequestfriendshipsAction(){
		$this->getHelper('viewRenderer')->setNoRender();
		//$iduser = $_POST['iduser'];
		$iduser = '10';
		$grfs = new Friendship_Model_Dbtable_RequestFriendship();
		$array_fr = $grfs ->getrequestfriendships($iduser);
		print_r($array_fr);
	}
	
	//Ajax 2s se su ly 1 lan

	
	public function test2Action(){
		$this->getHelper('viewRenderer')->setNoRender();
		$abc = new Friendship_Model_Dbtable_Friendship();
		$a = $abc->getFriends('16');
		print_r($a);
	}
	
	public function acceptrequestfriendsAction(){
		$this->getHelper('viewRenderer')->setNoRender();
		echo $iduser1 = $_POST['iduser1'];
		echo $iduser2 = $_POST['iduser2'];
		
		$acp = new Friendship_Model_Dbtable_RequestFriendship();
		$acp->acceptrequestfriends($iduser1, $iduser2);
	}
	
	public function unacceptrequestfriendsAction(){
		$this->getHelper('viewRenderer')->setNoRender();
		echo $iduser1 = $_POST['iduser1'];
		echo $iduser2 = $_POST['iduser2'];
		
		$uacp = new Friendship_Model_Dbtable_RequestFriendship();
		$uacp ->unacceptrequestfriends($iduser1, $iduser2);
	}
	
	


}

